/*******************************************************************************

           行选择器回调函数-在使用Plot模块, 直接绘制字符时的实现
显示示例：
   “001  字符串示例1     ”
   “002  字符串示例2     ” //光标位置选中时为反显
*******************************************************************************/
#include "RowSelector.h"
#include "Plot.h"
#include "StringEx.h"
#include <String.h>

//使用 RowSelector_Plot时，选择使用的字体, 不定义时默认8*16 ASC字体
//#define ROW_SELECTOR_FONT   

//-------------------------------行绘制函数--------------------------------
void RowSelector_cbPlotLine(const struct _RowSelector *pSelector,
                            unsigned char PageLine,//页内行
                            unsigned char IsCusor) //是否为光标行,0xff为空
{
  //准备字符串
  unsigned short Line = PageLine + pSelector->BaseLine;
  const struct _RowSelectorPlot *pInfo = pSelector->pPlot;
  char *pStr = pInfo->GetLineStr(Line);
  if(pStr == NULL) IsCusor = 0xff; //结束了
  unsigned short y = pSelector->Rect.y + PageLine * pInfo->h;
  //清空该行占位
  Plot_FullRect(pSelector->Rect.x, y, pSelector->Rect.w, pInfo->h);
  if(IsCusor == 0xff) return; //本行为空

  //被选择行使用反显方案
  unsigned char Color; 
  if(IsCusor){
    Color = Plot_GetPenColor();
    Plot_SetPenColor(Plot_GetBrushColor());
    Plot_SetBrushColor(Color);
  }
  //有行号时准备行号
  if(pInfo->NoLen){  
    char *pBuf = Value2StringMin(Line + 1, RowSelector_cbGetBuf(), pInfo->NoLen);
    *pBuf++ = ' ';
    *pBuf++ = ' ';
    strcpy(pBuf, pStr);
    pStr = RowSelector_cbGetBuf();
  }
  
  #if (ROW_SELECTOR_FONT == 20808) //使用双倍8*8字体实现
    Plot_StrAsc8_Scale2(pSelector->Rect.x, y, pStr, 0);
  #elif (ROW_SELECTOR_FONT == 1014)//使用双倍5*7高字体实现
    Plot_StrAsc57_Scale2(pSelector->Rect.x, y, pStr, 0);
  #elif (ROW_SELECTOR_FONT == 10808) //8*8字体
    Plot_StrAsc8(pSelector->Rect.x, y, pStr, 0);  
  #elif (ROW_SELECTOR_FONT == 1616) //16*16支持汉字字体
    Plot_String(pSelector->Rect.x, y, pStr, 0);      
  #else //未定义时为标准8*16 ASC字体
    Plot_StrAsc16(pSelector->Rect.x, y, pStr, 0);  
  #endif  
  //被选择行反显后恢复调色板
  if(IsCusor){
    Plot_SetBrushColor(Plot_GetPenColor());    
    Plot_SetPenColor(Color);
  }
}












